﻿using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Sustainalytics.ClientDW.Synchronization.SyncESGData.AbstractClassesAndInterfaces;
using Sustainalytics.SharedEntities.EsgResearch;

namespace Sustainalytics.ClientDW.Synchronization.SyncESGData.RPCompanyESGComputationResultLogic
{
    public class RPCompanyESGComputationResultOrchestrator : ICoreEsgSyncOrchestrator<EsgResearchProfile>, IComprehensiveEsgSyncOrchestrator<EsgResearchProfile>
    {
        private readonly RPCompanyESGComputationCommand rpCompanyEsgComputationCommand;
        private readonly RPCompanyESGComputationResultMapper rpCompanyEsgComputationResultMapper;

        public RPCompanyESGComputationResultOrchestrator(RPCompanyESGComputationCommand rpCompanyEsgComputationCommand, RPCompanyESGComputationResultMapper rpCompanyEsgComputationResultMapper)
        {
            AutoMapperConfig.RegisterMappings();

            this.rpCompanyEsgComputationCommand = rpCompanyEsgComputationCommand;
            this.rpCompanyEsgComputationResultMapper = rpCompanyEsgComputationResultMapper;
        }

        async Task ICoreEsgSyncOrchestrator<EsgResearchProfile>.OrchestrateAsync(IList<EsgResearchProfile> coreEsgResearchProfiles, IList<Guid> invalidatedCompaniesIds)
        {
            await OrchestrateAsync(coreEsgResearchProfiles, invalidatedCompaniesIds);
        }

        async Task IComprehensiveEsgSyncOrchestrator<EsgResearchProfile>.OrchestrateAsync(IList<EsgResearchProfile> comprehensiveEsgResearchProfiles, IList<Guid> invalidatedCompaniesIds)
        {
            await OrchestrateAsync(comprehensiveEsgResearchProfiles, invalidatedCompaniesIds);
        }

        private async Task OrchestrateAsync(IList<EsgResearchProfile> esgResearchProfiles, IList<Guid> invalidatedCompaniesIds)
        {
            await rpCompanyEsgComputationCommand.ExecuteAsync(rpCompanyEsgComputationResultMapper.MapManyToMany(esgResearchProfiles), invalidatedCompaniesIds);
        }
    }
}
